package com.kfm.dao;

import org.apache.commons.dbutils.QueryRunner;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 处理数据库表 upload_file的操作
 */
public class UploadFileDao {

    private QueryRunner runner = new QueryRunner();

    public int add(String ip, String name, String size, String type, String download) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/kfm", "root", "");) {
            String sql = "insert into upload_file(ip, file_name, file_size, file_type, download) values(?, ?, ?, ?, ?)";
            return runner.update(connection, sql, ip, name, size, type, download);
        } catch (SQLException e) {
            e.printStackTrace();
            return -1;
        }
    }
}
